$(function () {
    // 获取用户详情信息
    $.ajax({
        url: BigNew.user_detail,
        type: 'get',
        success: function (backData) {
            // console.log(backData);
            if (backData.code == 200) {
                $('#inputEmail1').val(backData.data.username);
                $('#inputEmail2').val(backData.data.nickname);
                $('#inputEmail3').val(backData.data.email);
                $('#inputEmail4').val(backData.data.password);
                $('.user_pic').attr('src', backData.data.userPic);
            }
        }
    });
    //头像预览
    $('#exampleInputFile').on('change', function () {
        if (this.files[0]) {
            let picUrl = URL.createObjectURL(this.files[0]);
            $('.user_pic').attr('src', picUrl)
        }
    })
    // 编辑用户信息
    $('.btn-edit').on('click', function (e) {
        e.preventDefault();
        let fd = new FormData($('#form')[0]);
        $.ajax({
            url: BigNew.user_edit,
            type: 'post',
            data: fd,
            contentType: false,
            processData: false,
            success: function (backData) {
                if (backData.code == 200) {
                    alert(backData.msg);
                    // window.parent.location.reload();
                    // window.parent.location.href = './login.html';
                    $.ajax({
                        url: BigNew.user_info,
                        type: 'get',
                        success: function (backData) {
                            // console.log(backData);
                            if (backData.code == 200) {
                                window.parent.$('.user_info img').attr('src', backData.data.userPic);
                                window.parent.$('.user_info span').html(`欢迎&nbsp;&nbsp;${backData.data.nickname}`);
                                window.parent.$('.user_center_link img').attr('src', backData.data.userPic);
                            };
                        }
                    });
                }
            }
        });
    });
});